using FitnessCenter.DataAccessLayer.DataModels;
using System.Data.Entity;

namespace FitnessCenter.DataAccessLayer.DataProviders
{
    public class FitnessCenterDataProvider : DbContext
    {
        public FitnessCenterDataProvider()
            : base("name=FitnessCenterDataProvider")
        {
        }

        public virtual DbSet<Activity> Activity { get; set; }
        public virtual DbSet<ActivityLog> ActivityLog { get; set; }
        public virtual DbSet<Person> Person { get; set; }
        public virtual DbSet<Subscribtion> Subscribtion { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Activity>()
                .Property(e => e.ActivityName)
                .IsUnicode(false);

            modelBuilder.Entity<Activity>()
                .HasMany(e => e.ActivityLog)
                .WithRequired(e => e.Activity)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Person>()
                .Property(e => e.FirstName)
                .IsUnicode(false);

            modelBuilder.Entity<Person>()
                .Property(e => e.LastName)
                .IsUnicode(false);

            modelBuilder.Entity<Person>()
                .Property(e => e.ThirdName)
                .IsUnicode(false);

            modelBuilder.Entity<Person>()
                .HasMany(e => e.Activity)
                .WithRequired(e => e.Person)
                .HasForeignKey(e => e.CoachID)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Person>()
                .HasMany(e => e.ActivityLog)
                .WithRequired(e => e.Person)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Person>()
                .HasMany(e => e.Subscribtion)
                .WithRequired(e => e.Person)
                .WillCascadeOnDelete(false);
        }
    }
}
